package m3d29;

public class qBaozipu extends Thread{
    //创包子
    private pBaozi bz;

    //构造为包子赋值
    public qBaozipu(pBaozi bz) {
        this.bz = bz;
    }

    @Override
    public void run() {
        while (true) {
            //保证两个线程包子和包子普只有一个执行
            synchronized (bz) {

                if (bz.flag == true) {
                    try {
                        bz.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                //被唤醒后执行，生产
                System.out.println("正在生产");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                bz.flag = true;
                //唤醒吃货
                bz.notify();
                System.out.println("已经生产好了");
            }
        }
    }
}
